// JavaScript Document

function allScroll(_Id,_Direction,_Speed,_Step,_Mode,_Pause){
	//sId:showBox的ID
	//nDirection:T为向上，R为向右，D为向下，L为向左
	//nSpeed:速度
	//nStep:步长
	//nMode:模式，1为单步滚动
	//nPause:暂停时间
	this.sId = _Id;
	this.nDirection = _Direction;
	this.nSpeed = _Speed;
	this.nStep = _Step;
	this.nMode = _Mode;
	this.nPause = _Pause;
}

allScroll.prototype ={
	scrollMove:function (_Id,_Direction,_Speed){
			this.sId = _Id?_Id:this.sId;
			this.nDirection = _Direction?_Direction:this.nDirection;
			this.nSpeed =  _Speed? _Speed:this.nSpeed;
			var oShow = document.getElementById(this.sId);
			var oShowBox=oShow.getElementsByTagName('div')[0];
			var oShow1=oShowBox.getElementsByTagName('div')[0];
			var oShow2=oShowBox.getElementsByTagName('div')[1];
			oShow2.innerHTML=oShow1.innerHTML;
			if(oShow.t){
				window.clearInterval(oShow.t);
			}
			oShow.t=window.setInterval(this.moving(oShow,oShow1,oShow2,this.nDirection),this.nSpeed);
	},
	
	stepMove:function (_Id,_Direction,_Speed,_Step,_Mode,_Pause){
			this.sId = _Id?_Id:this.sId;
			this.nDirection = _Direction?_Direction:this.nDirection;
			this.nSpeed =  _Speed? _Speed:this.nSpeed;
			this.nStep = _Step?_Step:this.nStep;
			this.nMode = _Mode?_Mode:this.nMode;
			this.nPause = _Pause?_Pause:this.nPause;
			var oShow = document.getElementById(this.sId);
			var oShowBox=oShow.getElementsByTagName('div')[0];
			var oShow1=oShowBox.getElementsByTagName('div')[0];
			var oShow2=oShowBox.getElementsByTagName('div')[1];
			oShow2.innerHTML=oShow1.innerHTML;
			if(oShow.t||oShow.s){
				window.clearInterval(oShow.t);
				window.clearTimeout(oShow.s);
			}
			oShow.t=window.setInterval(this.moving(oShow,oShow1,oShow2,this.nDirection,this.nSpeed,this.nStep,this.nMode,this.nPause),this.nSpeed);
	},
	
	moving:function (oShow,oShow1,oShow2,nDirection,nSpeed,nStep,nMode,nPause){
			return function () {
				start();
				function restart(){
					oShow.t=window.setInterval(start,nSpeed);	
				}
				function start(){
					if(nDirection=='T'){
						if(oShow2.offsetHeight-oShow.scrollTop<=0){
							oShow.scrollTop-=oShow1.offsetHeight	
						}
						else{
							oShow.scrollTop++;
						}
						if(oShow.scrollTop%nStep==0&&nMode==1){
							window.clearInterval(oShow.t);
							window.clearTimeout(oShow.s);
							oShow.s=setTimeout(restart,nPause);
						}
					}else if(nDirection=='R'){
						if(oShow.scrollLeft<=0){
							oShow.scrollLeft+=oShow1.offsetWidth	
						}
						else{
							oShow.scrollLeft--;
						}
						if(oShow.scrollLeft%nStep==0&&nMode==1){
							window.clearInterval(oShow.t);
							window.clearTimeout(oShow.s);
							oShow.s=setTimeout(restart,nPause);
						}
					}else if(nDirection=='D'){
						if(oShow.scrollTop<=0){
							oShow.scrollTop+=oShow1.offsetHeight	
						}
						else{
							oShow.scrollTop--;
						}
						if(oShow.scrollTop%nStep==0&&nMode==1){
							window.clearInterval(oShow.t);
							window.clearTimeout(oShow.s);
							oShow.s=setTimeout(restart,nPause);
						}
					}else if(nDirection=='L'){
						if(oShow2.offsetWidth-oShow.scrollLeft<=0){
							oShow.scrollLeft-=oShow1.offsetWidth	
						}
						else{
							oShow.scrollLeft++;
						}
						if(oShow.scrollLeft%nStep==0&&nMode==1){
							window.clearInterval(oShow.t);
							window.clearTimeout(oShow.s);
							oShow.s=setTimeout(restart,nPause);
						}
					}
				}
			}
	}
	}